<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <form>
      <input type="file" name="avatar" accept="image/*" placeholder="请选择头像" />
      <button>上传文件</button>
    </form>
    <img src="" alt="" class="avatar" style="width: 500px" />
    <script src="./axios.js"></script>
    <script>
      const form=document.querySelector('form')
      const avatar=document.querySelector('.avatar')
      form.addEventListener('submit',async function(e){
        e.preventDefault()
        const formData=new FormData(form)
        const {data:res}= await axios({
          url:'	http://ajax-api.itheima.net/api/file',
          method:'POST',
          data:formData
        })
         const url= res.data.url
        //  console.log(res.data.url);
         avatar.src=url
        
      })
    </script>
  </body>
</html>
